<docs>
  ## 首页
</docs>
<template>
  <!-- 内边距container 开始 -->
  <div class="container">
    <!-- <my-bread title="我的投递"></my-bread> -->
    <div class="header">
      <span class="arrow" @click="back_btn"></span>
      <h3 class="title">我的投递</h3>
    </div>
    <div class="navBar">
      <div :class="navBarFlag == '1' ? 'active': ''" @click='navBar(1)'>已投递</div>
      <div :class="navBarFlag == '2' ? 'active': ''" @click='navBar(2)'>看过我</div>
    </div>
    <div class="iContent" v-if="navBarFlag == '1'">
      <pagination-list
        @pullingDown="asyncFetch"
        :no-data="noData"
        class="search-result"
        :ajax-loading="ajaxLoading"
        id="pagination1"
      >
        <position
          v-for="item in zpxx"
          :key="item.dwdjid"
          :job="item.gwmc"
          :money="item.xc"
          :company="item.dwmc"
          :djsj="item.djsj"
          :dwdjid="item.dwdjid"
          :zpgwid="item.zpgwid"
          :jlid="item.jlid"
          :ygxs="item.ygxs"
          :sftxtdjl="item.sftxtdjl"
          :sfjpgw="item.sfjpgw"
          @link="link_bank"
        ></position>
      </pagination-list>
    </div>
    <div v-else>
      <pagination-list
        @pullingDown="asyncFetch1"
        :no-data="noData1"
        class="search-result"
        :ajax-loading="ajaxLoading1"
        id="pagination2"
      >
        <div
          class="item"
          @click="routerLink(item)"
          v-for="(item,n) in qyckjl"
          :key="n">
         <span class="company">{{item.dwmc}}</span>
         <span class="right">{{item.sfckg}}</span>
       </div>
      </pagination-list>
    </div>
  </div>
</template>
<script>
import $ from "@/common/js/axios";
import { validator } from "common/js/valid";
import PaginationList from "base/paginationList/paginationList";
import Position from "base/job/userjobList";

export default {
  name: "tdList",
  components: { Position, PaginationList },
  data() {
    return {
      ajaxLoading: false,
      ajaxLoading1: false,
      noData: false,
      noData1: false,
      zpxx:[],
      qyckjl:[],
      navBarFlag:1,
      _url1:'',
      _url2:'',
      form: {
        pageNum: 1,
        pageSize: "10"
      }
    };
  },
  methods: {
    navBar(val){
      if (val == this.navBarFlag) return
      if(this.navBarFlag == 1){
        this.navBarFlag = 2;
        this.GET_search(1,this._url2);
      }else{
        this.navBarFlag = 1;
        this.GET_search(1,this._url1);
      }
    },
    // link_bank跳转
    link_bank(gwid, dwid) {
      this.$router.push({ name: "newjobDetail" , query: { dm:gwid,_id:dwid,look:'1' } });
    },
    // 搜索职位
    GET_search(page = 1,url) {
      this.$loading = true;
      this.form.pageSize = '10';
      this.ajaxLoading =  this.navBarFlag == '1' ? true: false;
      this.ajaxLoading1 =  this.navBarFlag == '2' ? true: false;
      this.form.pageNum = page;

      $.get(url,{params:this.form})
        .then(res => {
          const data = res.returnData;
          if(this.navBarFlag == '1'){
            // 无查询结果
            console.log(data)
            if (+data.executeResult === 0) {
              this.noData = true;
              if (page === 1) {
                this.zpxx = [];
              }
            } else {
              this.noData = false;
              // 有数据
              if (page === 1) {
                this.zpxx = data.zpxx;
              } else {
                this.zpxx = this.zpxx.concat(data.zpxx);
              }
              if (data.zpxx.length<10) {
                this.noData = true;
              }
            }
          } else {
            // 无查询结果
            if (+data.executeResult === 0) {
              this.noData1 = true;
              if (page === 1) {
                this.qyckjl = [];
              }
            } else {
              this.noData1 = false;
              // 有数据
              if (page === 1) {
                this.qyckjl = data.qyckjl;
              } else {
                this.qyckjl = this.qyckjl.concat(data.qyckjl);
              }
              if (data.qyckjl.length<10) {
                this.noData1 = true;
              }
            }
          }
        })
        .finally(() => {
          this.ajaxLoading1 = false;
          this.ajaxLoading = false;
          this.$loading = false;
        });
    },
    // async fetach data
    asyncFetch(page) {
      this.GET_search(page, this._url1);
    },
    // async fetach data
    asyncFetch1(page) {
      this.GET_search(page, this._url2);
    },
    back_btn(){
      this.$router.push({ name: "personUser" });
    },
    routerLink(val){
      this.$loading = true;
      $.post("/grgl/jlckBc", {txcklx:'10',ckjlid:val.ckjlid})
        .then(res => {
          const data = res.returnData;
          if (+data.executeResult === 1) {
            this.$router.push({path:'/company/newcompanyDetail',query:{id: val.dwdjid, look:'1'}})
          }
        })
        .finally(() => {
          this.$loading = false;
        });
    }
  },
  created() {
    // this.form.qwgjz = this.$store.getters.qwgjz;
    this._url1 = '/grgl/tdxxCx';
    this._url2 = '/grgl/qyckjlCx';
    this.$nextTick(_=>{
      if(this.$route.query.look == 1){
        this.navBarFlag = '2';
        this.GET_search(1,this._url2);
      }else{
        this.navBarFlag = '1';
        this.GET_search(1,this._url1);
      }
    })
  }
};
</script>
<style scoped lang="scss">
@import "~common/scss/var.scss";
.navBar{
  display: flex;
  div {
    flex: 1;
    height: 100px;
    line-height: 100px;
    text-align: center;
    border-right: $border;
  }
  div:last-child{
    border-right:none;
  }
}
.item{
  margin: $height-base/10 0;
  border-radius: $radius-base3;
  background-color: #fff;
  padding: $font-size-base 15px $margin-base;
}
.right{
  float: right;
}
.company {
  background: url("~common/images/company.png") 0 $padding-base-half
    no-repeat;
  background-size: $height-input_base;
  padding-left: $padding-base-half * 4;
  width: 64%;
}
.active{
  color: $color-base;
}
</style>
